import axios from 'axios'
axios.defaults.baseURL="http://127.0.0.1:8000"
axios.defaults.timeout = 1000*10
// axios.defaults.headers.post['Content-Type']='application/json';
axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.headers.put ['Content-Type'] = 'application/json';
// axios.defaults.headers.delete['Content-Type'] = 'application/json';



export function axios_get(url,params){
    return new Promise(
        (resolve,reject)=>{
            axios.get(url,{params:params})
            .then(res=>{
                resolve(res.data)
            }).catch(err=>{
                reject(err.data)
            })
        }
    )
}

export function axios_post(url,data){
    return new Promise(
        (resolve,reject)=>{
            axios.post(url,JSON.stringify(data))
            .then(res=>{
                resolve(res.data)
            }).catch(err=>{
                reject(err.data)
            })
        }
    )
}

export function axios_put(url,data){
    return new Promise(
        (resolve,reject)=>{
            axios.put(url,JSON.stringify(data))
            .then(res=>{
                resolve(res.data)
            }).catch(err=>{
                reject(err.data)
            })
        }
    )
}

export function axios_delete(url,params){
    return new Promise(
        (resolve,reject)=>{
            axios.delete(url,{params:params})
            .then(res=>{
                resolve(res.data)
            }).catch(err=>{
                reject(err.data)
            })
        }
    )
}
